package top.riske.animalhazardassessment.animal.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import top.riske.animalhazardassessment.animal.service.AnimalService;
import top.riske.animalhazardassessment.common.entity.Animal;
import top.riske.animalhazardassessment.common.http.request.AnimalInputRequest;

import java.util.List;

@Tag(name = "AnimalController",description = "动物信息接口")
@RestController
public class AnimalController {

    @Resource
    private AnimalService animalService;

    @Operation(summary = "查询所有动物信息")
    @GetMapping("/animal/get")
    public List<Animal> selectAnimals() {
        return animalService.getAnimals();
    }

    @Operation(summary = "删除动物信息")
    @GetMapping("/animal/delete")
    public void deleteAnimal(@RequestParam Long animalId) {
        Animal animal = new Animal();
        animal.setId(animalId);
        animalService.deleteAnimal(animal);
    }

    @Operation(summary = "更新动物信息")
    @PostMapping("/animal/update")
    public boolean updateAnimal(@RequestBody Animal animal) {
        int res = animalService.updateAnimal(animal);
        return res > 0;
    }

    @Operation(summary = "新增动物信息")
    @PostMapping("/animal/add")
    public Animal addAnimal(@RequestBody AnimalInputRequest animal) {
        return animalService.addAnimal(animal.toEntity());
    }



}
